<template>
  <div>
    <lb-picker
      ref="picker"
      mode="multiSelector"
      @confirm="handleConfirm"
      :level="2"
      :list="cate"
      :props="myProps"
    ></lb-picker>
  </div>
</template>
<script>
import LbPicker from "@/components/lb-picker";
export default {
  props:{
    show:{
      type: Object,
    }
  },
  data() {
    return {
      lawer: [],
      myProps: {
        // picker 修改键名
        label: "title",
        value: "id",
        children: "children"
      },
      cate: [] // 擅长领域，大小类
    };
  },
  watch: {
    show(newVal, oldVal){
      console.log(newVal);
      newVal.show ? this.$refs.picker.show() : this.$refs.picker.hide()
    }
  },
  created() {
    let that = this
    uni.request({
        url: that.$store.state.baseUrl + "member.index",
        data: {
          op: "getConsultation"
        },
        success(res) {
          that.cate = res.data.data.list; // 分类数据
          let defaultData = []
          defaultData[0] = {
            title: that.cate[0].title,
            id: that.cate[0].id
          }
          defaultData[1] = {
            title: that.cate[0].children[0].title,
            id: that.cate[0].children[0].id
          }
          that.$emit('defaultData',defaultData)
        }
      });
  },
   components: {
    LbPicker
  },
  methods: {
    handleConfirm(e, i) {
      let that = this;
      let big = e.index[0];
      let small = e.index[1];
      let bigText = {
        title: this.cate[big].title,
        id: this.cate[big].id
      }
      let smallText = {
        title: this.cate[big].children[small].title,
        id: this.cate[big].children[small].id
      }
      this.$emit('getCate',bigText,smallText)
    }
  }
};
</script>
<style lang='less' scoped>
</style>